package com.stockz.core.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;

import org.springframework.util.StringUtils;

@Entity
public class Exchange implements Serializable,Comparable<Exchange> {
	private static final long serialVersionUID = -7558034070956149258L;

	private String code;
	private String name;
	
	@Override
	public boolean equals(Object obj) {
		if(obj != null && obj instanceof Exchange){
			Exchange exchange = (Exchange)obj;
			if(StringUtils.hasText(code) && StringUtils.hasText(exchange.code)){
				return code.equalsIgnoreCase(exchange.code);
			}
		}
		return super.equals(obj);
	}
	
	@Override
	public int hashCode() {
		if(StringUtils.hasText(name)){
			return name.hashCode();
		}
		return super.hashCode();
	}
	
	@Override
	public String toString() {
		return code+" - "+name;
	}
	
	
	public int compareTo(Exchange exchagne) {
		if(StringUtils.hasText(name) && StringUtils.hasText(exchagne.name)){
			return name.compareToIgnoreCase(exchagne.name);
		}
		return 0;
	}
	
	@Id
	@Column
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	
	@Column
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
}
